require(zTree)

zTT1= zTreeTables("October20ChangingPriors.xls")
subjects1=zTT1$subjects

zTT2= zTreeTables("October23ChangingPriors.xls")
subjects2=zTT2$subjects
subjects2$Subject=subjects2$Subject+100

zTT3= zTreeTables("October24ChangingPriors.xls")
subjects3=zTT3$subjects
subjects3$Subject=subjects3$Subject+200

subjects=rbind(subjects1,subjects2,subjects3)

priors=c(0.5,0.85)

#Clean data
subjects$responder=(subjects$"response1[50]">0)
subjects=subset(subjects,responder>0)

uidlist=unique(subjects$Subject)

#find N
#**
length(uidlist)
#**

#create a frame with observations
obsframe=data.frame(uid=vector('numeric'),block=vector('numeric'), priorA=vector('numeric'), number=vector('numeric'), state=vector('numeric'), response=vector('numeric'))
for(i in 1:length(uidlist)){
playframe=subjects[i,]
uidplace=uidlist[i]

#block 1
for (j in 1:50){
blockplace=1
priorplace=priors[playframe[1,682]]
numberplace=j
stateplace=playframe[1,(735+j)]
responseplace=playframe[1,(71+j)]
addframe=data.frame(uid=uidplace,block=blockplace, priorA=priorplace, number=numberplace, state=stateplace, response=responseplace)
obsframe=rbind(obsframe,addframe)
}

#block 2
for (j in 1:50){i
blockplace=2
priorplace=priors[playframe[1,683]]
numberplace=j
stateplace=playframe[1,(785+j)]
responseplace=playframe[1,(221+j)]
addframe=data.frame(uid=uidplace,block=blockplace, priorA=priorplace, number=numberplace, state=stateplace, response=responseplace)
obsframe=rbind(obsframe,addframe)

}

}

expframe=obsframe

#definitions
expframe$priorB=1-expframe$priorA
expframe$Aresponse=(expframe$response==1)
expframe$Bresponse=(expframe$response==2)
expframe$stateA=(expframe$state==1)
expframe$stateB=(expframe$state==2)
expframe$correct=(expframe$response==expframe$state)
